import {combineReducers} from 'redux';

import {
    REQUEST_USERS,
    RECEIVE_USERS,
} from '../actions/userAction';


let userTableDefaultState = {
    //表格loading
    loading: false,
    //表格数据
    list: [],
};

export const userList = (state = userTableDefaultState, action) => {
    switch (action.type) {
        case REQUEST_USERS:
            return {...state, ...{loading:true}};
        case RECEIVE_USERS:
            return {...state, ...{loading: false, list: action.data.list}};
        default:
            return state;
    }
};


let paginationDefaultState = {
    //表格分页
    current: 1,
    pageSize: 10,
    total: 0,
};

export const userListPage = (state = paginationDefaultState, action) => {
    switch (action.type) {
        case RECEIVE_USERS:
            return {...state, ...{
                current: action.data.pageNum,
                pageSize: action.data.pageSize,
                total: action.data.total,
            }};
        default:
            return state;
    }
};


export const userAdd = (state = paginationDefaultState, action) => {
    switch (action.type) {
        case RECEIVE_USERS:
            return {...state, ...{
                current: action.data.pageNum,
                pageSize: action.data.pageSize,
                total: action.data.total,
            }};
        default:
            return state;
    }
};

